<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('本单位人员管理')" />
</head>
<body class="gray-bg">
<div class="container-div" id="bendanweirenyuanguanli_list">
    <div class="row">

        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 80px !important;">用户名称&nbsp;&nbsp;</label>
                            <input style="width: 150px !important;" type="text" v-model="username"/>
                        </li>
                        <li class="sousuo">
                            <a class="btn btn-success btn-md" @click="bindUserList"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-md" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <div shiro:hasAnyRoles="zhongxin_superadmin,dept_superadmin" class="btn-group-md" id="toolbar" role="group">
                <button class="btn btn-primary btn-md dim" @click="toAdd()">
                    <i class="fa fa-plus"></i> 新增
                </button>
            </div>
            <table id="bootstrap-table" class="table table-hover table-primary table-striped">
                <thead>
                <tr>
                    <th style="width: 50px;">序号</th>
                    <th>登录账号</th>
                    <th>用户名称</th>
                    <th style="width: 300px;">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(userItem,index) in userlist"  v-if="userlist.length > 0">
                    <td v-text="index+1"></td>
                    <td style="vertical-align: middle; text-align: center;" v-text="userItem.loginname"></td>
                    <td style="vertical-align: middle; text-align: center;" v-text="userItem.username"></td>
                    <td style="vertical-align: middle; text-align: center;" v-text="">
                        <button class="btn btn-success btn-md" @click="toChakan(userItem)">查看</button>
                        <button shiro:hasAnyRoles="zhongxin_superadmin,dept_superadmin"
                                class="btn btn-warning btn-md" @click="toEdit(userItem)">修改</button>
                        <!--<button v-if="roleid==danweichaoguanroleid||roleid==zjzxroleid"
                                class="btn btn-warning btn-rounded btn-md" @click="resetPwd(userItem)">修改密码</button>-->
                        <button shiro:hasAnyRoles="zhongxin_superadmin,dept_superadmin"
                                class="btn btn-danger btn-md" @click="Remove(userItem.userid)">删除</button>
                    </td>
                </tr>
                <tr v-if="userlist.length == 0">
                    <td style="text-align: center; vertical-align: middle" colspan="4">查无数据</td>
                </tr>
                </tbody>
            </table>

        </div>

        <!--编辑-->
        <div th:replace="system/yonghuguanli/modal_bendanweirenyuan::bendanweirenyuan"></div>
        <!--查看-->
        <div th:replace="system/yonghuguanli/modal_chakan::chakan"></div>

    </div>
</div>

<th:block th:include="include :: footer" />

<script th:inline="javascript">
    var vm_bendanweirenyuanguanli_list = new Vue({
        el: "#bendanweirenyuanguanli_list",
        data: {
            deptid: $("#deptid").val(),
            jigoujibie: $("#jigoujibie").val(),
            roleid: $("#roleid").val(),

            userlist: [],// 列表list

            //查询用字段
            username: "",

            pwd:"",

            //edit字段
            editItem:{
                loginname: "",
                phonenumber: "",
                email: "",
                password:"",
                username:"",
                suoshubumen:"",//所属部门
                bangongdianhua:"",//办公电话
                remark:""
            },

            //编辑标记1新增2修改
            editflag:"",
        },
        created: function () {
            var _this = this;

            _this.bindUserList();

        },
        methods: {

            bindUserList: function () {
                var _this = this;
                $.post('/system/user/findbydeptidandusername', {
                    deptid: _this.deptid,
                    username:_this.username,
                    rdm: Math.random()
                }, function (ppData) {
                    if (ppData != null) {
                        var data = ppData.resultContent;
                        _this.userlist = data;
                    }
                }, "json");
            },

            resetPwd:function (user) {
                var url = 'system/user/yonghuguanli/resetPwd/' + user.userid;
                $.modal.open("重置密码", url, '800', '300');
            },

            toAdd:function () {
                var  _this = this
                _this.editflag = "1";
                _this.editItem = {
                    loginname: "",
                    phonenumber: "",
                    email: "",
                    password:"",
                    username:"",
                    suoshubumen:"",//所属部门
                    bangongdianhua:"",//办公电话
                    remark:""
                }
                $("#myModalLabel").html("新增本单位普通管理员");
                $("#editModal").modal();
            },

            toEdit:function (userItem) {
                var  _this = this
                _this.editflag = "2";
                _this.editItem = {
                    phonenumber: userItem.phonenumber,
                    email: userItem.email,
                    sex:userItem.sex,
                    username:userItem.username,
                    loginname: userItem.loginname,
                    userid:userItem.userid,
                    suoshubumen:userItem.text1,//所属部门
                    bangongdianhua:userItem.text2,//办公电话
                    remark:userItem.remark,
                }
                $("#myModalLabel").html("修改本单位普通管理员");
                $("#editModal").modal();
            },
            toChakan:function (userItem) {
                var  _this = this
                _this.editItem = {
                    phonenumber: userItem.phonenumber,
                    email: userItem.email,
                    sex:userItem.sex,
                    username:userItem.username,
                    loginname: userItem.loginname,
                    userid:userItem.userid,
                    suoshubumen:userItem.text1,//所属部门
                    bangongdianhua:userItem.text2,//办公电话
                    remark:userItem.remark
                }
                $("#myModalLabel2").html("查看");
                $("#chakanModal").modal();
            },
            add:function () {
                var _this = this;
                var prefix = "/system/user";
                $("#form-user-edit").validate({
                    onkeyup: false,
                    rules: {
                        loginName: {
                            minlength: 2,
                            maxlength: 20,
                            remote: {
                                url:  prefix + "/checkLoginNameUnique",
                                type: "post",
                                dataType: "json",
                                data: {
                                    "loginName": function () {
                                        return $.common.trim(_this.editItem.loginname);
                                    }
                                },
                                dataFilter: function (data, type) {
                                    return $.validate.unique(data);
                                }
                            }
                        },
                        password: {
                            required:true,
                            minlength: 8,
                            maxlength: 20
                        },
                    },
                    messages: {
                        "loginName": {
                            remote: "用户已经存在"
                        },
                    },
                    focusCleanup: true
                });
                if ($.validate.form("form-user-edit") && checkpwd(0, _this.editItem.password)) {
                    $.post('/system/user/customadd', {
                        deptId: _this.deptid,
                        loginName:_this.editItem.loginname,
                        phonenumber:_this.editItem.phonenumber,
                        email:_this.editItem.email,
                        password:_this.editItem.password,
                        userName:_this.editItem.username,
                        roleIds:_this.jigoujibie=="0"?"101":"103",
                        suoshubumen:_this.editItem.suoshubumen,
                        bangongdianhua:_this.editItem.bangongdianhua,
                        remark:_this.editItem.remark,
                        rdm: Math.random()
                    }, function (ppData) {
                        if(ppData.code==0){
                            $("#editModal").modal("hide");
                            _this.editItem = {
                                loginname: "",
                                phonenumber: "",
                                email: "",
                                password:"",
                                username:"",
                                suoshubumen:"",//所属部门
                                bangongdianhua:"",//办公电话
                                remark:""
                            }
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "新增成功!",
                            });
                            _this.bindUserList();
                        }else {
                            layer.alert(ppData.msg)
                        }
                    }, "json");
                }
            },

            edit:function () {
                var _this = this;
                var prefix = "/system/user";
                $("#form-user-edit").validate({
                    onkeyup: false,
                    rules:{
                        userName:{
                            required:true
                        },
                        password: {
                            minlength: 8,
                            maxlength: 20
                        },
                    },
                    messages: {
                    },
                    focusCleanup: true
                });
                if ($.validate.form("form-user-edit") && checkpwd(0, _this.editItem.password)) {
                    $.post('/system/user/customedit', {
                        userId:_this.editItem.userid,
                        phonenumber:_this.editItem.phonenumber,
                        email:_this.editItem.email,
                        userName:_this.editItem.username,
                        loginName:_this.editItem.loginname,
                        suoshubumen:_this.editItem.suoshubumen,//所属部门
                        bangongdianhua:_this.editItem.bangongdianhua,//办公电话
                        remark:_this.editItem.remark,
                        password:_this.editItem.password,
                        rdm: Math.random()
                    }, function (ppData) {
                        if(ppData.code==0){
                            $("#editModal").modal("hide");
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "修改成功!",
                            });
                            _this.bindUserList()
                        }else {
                            layer.alert(ppData.msg)
                        }
                    }, "json");
                }
            },
            Remove:function (userId) {
                var _this = this
                $.modal.confirm("确认删除", function() {
                    $.operate.get("/system/user/customdelete?userid="+userId,function () {
                        _this.bindUserList()
                    })

                });
            }
        },
    })
</script>

</body>
</html>
